// 大数据第九题 
// author ： lbc
package homework1;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class deleteFile {
    public static void main(String[] args) throws IOException, URISyntaxException {
        Configuration conf = new Configuration();
        String hdfsPath = "hdfs://localhost:9000";
        FileSystem hdfs = FileSystem.get(new URI(hdfsPath), conf);
        String filePath = "hdfstest/input.txt";
        if(!fileHadoopExist(hdfs, filePath)){
            if(remove(hdfs, filePath))
                System.out.println("file delete successfully!");
        }
        else{
            System.out.println("err: file not exist!");
        }

        hdfs.close();
    }
    
    public static boolean remove(FileSystem fs, String file_path) throws IOException {
        boolean res = fs.delete(new Path(file_path), false);
        return res;
    }

    public static boolean fileHadoopExist(FileSystem fs, String file_path) throws IOException {
        return fs.exists(new Path(file_path));
    }
}

